package cz.gelion.shylock.invoice.web.comp

import org.apache.wicket.markup.html.form.Form
import org.apache.wicket.model.IModel
import cz.gelion.shylock.invoice.web.Application
import cz.gelion.shylock.invoice.Log

class TaForm[T](id:String,model:IModel[T], submit:T=>Unit=(t:T)=>{}) extends Form[T](id,model) with Log {

  def this(id:String) = this(id,null)
  
  override def onSubmit() = {
     log.trace("comitting transaction")
     Application.em.getTransaction.commit;
     submit(model.getObject)
   }
    
    
   override def beforeUpdateFormComponentModels() = {
     log.trace("merging model object")
     setModelObject(Application.em.merge(getModelObject()))
     log.trace("starting transaction")
     Application.em.getTransaction.begin;   
   }
   
  
}